function [uniqueCompounds, graphNodes, graphEdges ] = ...
    create_graph_level(metabolitesOnEachLevel, graphNodes, graphEdges)
 
    tStart = tic;
    graph_idx = numel(graphNodes) / 2;
    
    elementsToExclude = [];
    if evalin('base','exist(''elementsToExclude'',''var'')')
        elementsToExclude = evalin('base', 'elementsToExclude');
    end
    
    defines = evalin('base', 'defines');
    listOfMetabolitesOnActiveLevel = metabolitesOnEachLevel{size(metabolitesOnEachLevel,2)};
    listOfMetabolitesByReaction=[];
    
    reactionType = '\w.*(?<=main$)|\w.*(?<=trans$)';
   
    for i = 1:size(listOfMetabolitesOnActiveLevel,1)
        mainCompoundIndex = find(strcmp(graphNodes(:,1),listOfMetabolitesOnActiveLevel(i,:)),1);
        compoundStructure = get_compound_information(listOfMetabolitesOnActiveLevel{i,:});
        listOfReactions = compoundStructure.REACTIONS;

        for y = 1:length(listOfReactions)
           if ~strcmp(listOfReactions{1,y},elementsToExclude)
               reaction_struct = get_reaction_information(listOfReactions{1,y});
               if strcmp(defines.isThermodinamicUsed, 'true')
                   isCorrectDirection = get_reaction_dirrection_by_thermodinamics(listOfReactions{1,y}, ...
                   reaction_struct.EQUATION, listOfMetabolitesOnActiveLevel{i,:});
               else
                   isCorrectDirection = true;
               end

               if isCorrectDirection
                  listOfRPairs = {};
                  if ~isempty(reaction_struct.RPs)
                    for n = 1:length(reaction_struct.RPs)
                         if ~isempty(regexp(reaction_struct.RPs{n},reactionType,'match'))
                             if ~isempty(regexp(reaction_struct.RPs{n},listOfMetabolitesOnActiveLevel{i,:}))
                                  listOfRPairs = {listOfRPairs{1,:},reaction_struct.RPs{n}};
                             end
                         end
                    end
                    isReactionFound = false;
                    if ~ismember(listOfReactions{1,y},graphNodes(:,1)) 
                        graph_idx = graph_idx + 1;
                        graphNodes = [graphNodes; {listOfReactions{1,y},graph_idx}];
                        graphEdges = [graphEdges; mainCompoundIndex,graphNodes(graph_idx,2)];
                    else
                        isReactionFound = true;
                    end

                    for k = 1:length(listOfRPairs)
                        compoundsPair = regexp(listOfRPairs{k}, 'C.....', 'match');
                        compoundIndex = '';
                        if char(listOfMetabolitesOnActiveLevel(i,:)) == char(compoundsPair(1))
                             if ~strcmp(char(compoundsPair(2)),elementsToExclude)
                                 compoundIndex = char(compoundsPair(2));
                                 listOfMetabolitesByReaction = [listOfMetabolitesByReaction; compoundIndex];                       
                             end                      
                        elseif char(listOfMetabolitesOnActiveLevel(i,:)) == char(compoundsPair(2))
                            if ~strcmp(char(compoundsPair(1)),elementsToExclude)
                                compoundIndex = char(compoundsPair(1));
                                listOfMetabolitesByReaction = [listOfMetabolitesByReaction; compoundIndex];
                            end
                        end
                        reactionIndex = find(strcmp(graphNodes(:,1),listOfReactions{1,y}),1);
                        if ~isempty(compoundIndex)
                            if ~strcmp(compoundIndex,graphNodes) 
                                graph_idx = graph_idx + 1;
                                graphNodes = [graphNodes; {compoundIndex, graph_idx}];  
                                graphEdges = [graphEdges; reactionIndex, graphNodes(graph_idx,2)];
                            else
                                existingCompound = find(strcmp(graphNodes(:,1),compoundIndex),1);
                              %  if ~isReactionFound
                                    graphEdges = [graphEdges; reactionIndex, {existingCompound}];
                            %    end
                            end 
                        end
                     end 
                  end
               end
           end
        end
    end
    uniqueCompoundsList = unique(listOfMetabolitesByReaction, 'rows');
    for i = 1:size(metabolitesOnEachLevel,2) + 1
        if i <= size(metabolitesOnEachLevel,2)
            uniqueCompounds{1,i} = metabolitesOnEachLevel{1,i};
        else
            try
               uniqueCompounds{1,i} = cellstr(uniqueCompoundsList);
            catch err
               disp('No compounds by reaction'); 
            end
        end
    end
    tElapsedConstructGraph = toc(tStart)
end
